package com.zhenzhang.myblog.exception;

import com.zhenzhang.myblog.utils.JsonResult;

public class JsonException extends RuntimeException {
    private final JsonResult res;
    public JsonException() {
        var res = JsonResult.getInstance();
        res.setCode(500);
        res.setMessage("服务器未知错误");
        this.res = res;
    }

    public JsonException(int code, String message) {
        this.res = JsonResult.getInstance(code, message);
    }

    public JsonException(JsonResult res) {
        this.res = res;
    }

    public JsonResult getResult() {
        return this.res;
    }

    public int getCode() {
        return res.getCode();
    }

    @Override
    public String getMessage() {
        return res.getMessage();
    }
}
